package com.alibaba.citrus.cr.common.enums.ordercenter;

import com.google.common.collect.Lists;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum FulfillmentTypeEnum {
    // 集团订单履约方式
    CENTRAL_TO_CENTRAL("100", "大仓发货大仓收货"),
    CENTRAL_TO_EXTERNAL("110", "大仓发货外仓收货"),
    EXTERNAL_TO_CENTRAL("120", "外仓发货大仓收货"),
    EXTERNAL_TO_EXTERNAL("130", "外仓发货外仓收货"),
    VIRTUAL("200", "虚拟移库"),

    // 分公司订单履约方式
    CENTRAL_DELIVERY("300", "大仓履约"),
    EXTERNAL_TO_DELIVERY("400", "外仓履约")
    ;

    private final String code;
    private final String desc;

    FulfillmentTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static FulfillmentTypeEnum of(String code) {
        return Arrays.stream(FulfillmentTypeEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        FulfillmentTypeEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : "";
    }

    public static List<String> codes() {
        return Arrays.stream(FulfillmentTypeEnum.values()).map(FulfillmentTypeEnum::getCode).collect(Collectors.toList());
    }

    public static List<String> returnCodes() {
        return Lists.newArrayList(CENTRAL_TO_CENTRAL.code, CENTRAL_TO_EXTERNAL.code, VIRTUAL.code);
    }

    public static List<String> salesCodes() {
        return Lists.newArrayList(CENTRAL_TO_CENTRAL.code, EXTERNAL_TO_CENTRAL.code, VIRTUAL.code);
    }
}
